/**
 * 生成可直接使用的样式对象
 * @param originalStyle 接口返回的原始数据对象{}
 * @param styleList 需要用到的样式属性[]
 * @returns {{}}
 */
export default function formatStyle(originalStyle, styleList) {
  if (originalStyle?.constructor === String) {
    originalStyle = JSON.parse(originalStyle);
  }
  if (Array.isArray(styleList) && originalStyle?.constructor === Object) {
    const result = {};
    Object.keys(originalStyle).filter(item => styleList.includes(item)).forEach(item => {
      if (originalStyle[item]) {
        if (originalStyle[item]?.constructor === Number) {
          result[item] = `${originalStyle[item] * 2}rpx`;
        } else {
          result[item] = originalStyle[item];
        }
      }
    });

    return result;
  } else {
    throw new Error('参数格式不正确');
  }
}
